import { Component, OnInit } from '@angular/core';
import { StorageService } from 'src/app/services/storage.service';

@Component({
  selector: 'app-search',
  templateUrl: './search.component.html',
  styleUrls: ['./search.component.css']
})
export class SearchComponent implements OnInit {

  constructor(public storage:StorageService) {
  }

  ngOnInit(): void {
    console.log('页面刷新会出发这个声明周期函数')
    var searchlist = this.storage.get('searchlist')
    if(searchlist){
      this.historyList = searchlist;
    }
  }

  public keyword:string='';
  public historyList:any=[];
  doSearch(){
    if(this.historyList.indexOf(this.keyword) == -1){
      this.historyList.push(this.keyword)
      this.storage.set('searchlist',this.historyList);
    }

    this.keyword=''
  }
  doDelete(key:any){
    // alert(key)
    this.historyList.splice(key,1);
    this.storage.set('searchlist',this.historyList);

  }

}
